package com.aikon.wht.designPattern.consumer;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author haitao.wang http://www.bestwonderful.com
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Product {

    List<String> products = new ArrayList<>();

    public synchronized void produce(String s) {
//        System.out.println("Produce :" + s);
        products.add(s);
    }

    public synchronized void consume() {
        String toConsume = products.get(products.size() - 1);
//        System.out.println("Consume :" + toConsume);
        products.remove(toConsume);
    }

    public boolean isEmpty() {
        return CollectionUtils.isEmpty(products);
    }
}
